<?php
require_once('App-Top.php');
require_once('Authorizer.php');
require_once('DBConfigQuery.php');
require_once('GenFunctions.php');
require_once('../config.inc.php');
require_once('../Validation.php');

// Check if it is Member Mng
if (isset($_SESSION['SESS_USER_TYPE'])) {
    if (!isUserType_Members($_SESSION['SESS_USER_TYPE'])) {
        header("Location: AdminIndex.php");
        exit();
    }
}

// Check if the Get is set and not empty and that complies with the right number of digits
if ( !isset($_GET['eventid']) ) {
    if (isset($_SESSION['FORMS']['FormEditEvent'])){ unset ($_SESSION['FORMS']['FormEditEvent']); }
    header("Location: AdminEventEdit.php");
    exit();
}
if ( empty($_GET['eventid']) ) {
    if (isset($_SESSION['FORMS']['FormEditEvent'])){ unset ($_SESSION['FORMS']['FormEditEvent']); }
    header("Location: AdminEventEdit.php");
    exit();
}

$q = sprintf($Q_ALL_Event, (int) $_GET['eventid']);
$r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

if (mysqli_num_rows($r) == 1) {
    $_SESSION['FORMS']['FormEditEvent'] = mysqli_fetch_array($r, MYSQLI_ASSOC);
    mysqli_free_result($r);
    mysqli_close($dbc);
} else {
    // Free DB
    if (isset($_SESSION['FORMS']['FormEditEvent'])){ unset ($_SESSION['FORMS']['FormEditEvent']); }
    mysqli_free_result($r);
    mysqli_close($dbc);
    die("Query failed");
}


//TODO: Validate fields and show errors here...

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Event Edit</title>
        <link href="StyleControl.css" rel="stylesheet" type="text/css" />
        <link type="text/css" href="../JQuery/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
        <script type="text/javascript" src="../JQuery/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="../JQuery/jquery-ui-1.7.2.custom.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $(".datepicker-inline").datepicker();
                $(".datefield").datepicker();
            });
        </script>
    </head>
    <body>

        <div id="sidebar">
            <h3>Reports</h3>
            <ul>
                <li><a href="#">Gate List</a></li>
                <li><a href="#">Members List</a></li>
            </ul>


            <?php
            require_once('MenuAdmin.php');
            ?>
        </div>

        <div id="mainbody">
            <h1>Event Edition</h1> <br />

            <form id="editEvent" name="editEvent" method="POST" action="AdminEventEditConfirm.php" class="compactform">
                <fieldset class="clearfix">

                    <div class="threeper">
                        <label for="etitle">Title
                        <input name="etitle" type="text" id="etitle" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['Title'])) { echo $_SESSION['FORMS']['FormEditEvent']['Title']; } ?>"  /></label>

                        <label for="espkrname">Speaker Name
                        <input name="espkrname" type="text" id="espkrname" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['SpeakerName'])) { echo $_SESSION['FORMS']['FormEditEvent']['SpeakerName']; } ?>"  /></label>

                        <label for="espkrinfo">Speaker Info
                        <input name="espkrinfo" type="text" id="espkrinfo" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['SpeakerInfo'])) { echo $_SESSION['FORMS']['FormEditEvent']['SpeakerInfo']; } ?>"  /></label>

                    </div>

                    <div class="twoper">
                        <label for="edate"> Date
                        <input name="edate" type="text" id="edate" class="datefield" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['Date'])) { echo changeSQLDateToFormDate($_SESSION['FORMS']['FormEditEvent']['Date']); } ?>"  /></label>

                        <label for="etime"> Time
                        <select name="etime" id="etime" style="width:8em;">
                            <?php
                                  $hours = array('00:00 AM', '00:30 AM', '01:00 AM', '01:30 AM', '02:00 AM', '02:30 AM', '03:00 AM', '03:30 AM', '04:00 AM', '04:30 AM', '05:00 AM', '05:30 AM',
                                                 '06:00 AM', '06:30 AM', '07:00 AM', '07:30 AM', '08:00 AM', '08:30 AM', '09:00 AM', '09:30 AM', '10:00 AM', '10:30 AM', '11:00 AM', '11:30 AM',
                                                 '12:00 PM', '12:30 PM', '01:00 PM', '01:30 PM', '02:00 PM', '02:30 PM', '03:00 PM', '03:30 PM', '04:00 PM', '04:30 PM', '05:00 PM', '05:30 PM',
                                                 '06:00 PM', '06:30 PM', '07:00 PM', '07:30 PM', '08:00 PM', '08:30 PM', '09:00 PM', '09:30 PM', '10:00 PM', '10:30 PM', '11:00 PM', '11:30 PM');

                                  $timeToMatch = '12:00 PM';
                                  if (isset($_SESSION['FORMS']['FormEditEvent']['Time']))
                                  {
                                     $timeToMatch = $_SESSION['FORMS']['FormEditEvent']['Time'];
                                  }

                                  foreach($hours as $hour)
                                  {
                                      if (strcasecmp($hour, $timeToMatch) == 0)
                                      {
                                         echo "<option value='$hour' selected='selected'>$hour</option>";
                                      }
                                      else
                                      {
                                          echo "<option value='$hour'>$hour</option>";
                                      }
                                  }
                            ?>
                        </select>
                        </label>

                    </div>

                    <div class="twoper">
                        <label for="evenuename">Venue Name
                        <input  name="evenuename" type="text" id="evenuename" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['VenueName'])) { echo $_SESSION['FORMS']['FormEditEvent']['VenueName']; } ?>"  /></label>


                        <label for="evenueinfo">Venue Info
                        <input  name="evenueinfo" type="text" id="evenueinfo" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['VenueInfo'])) { echo $_SESSION['FORMS']['FormEditEvent']['VenueInfo']; } ?>"  /></label>

                    </div>

                    <div class="twoper">
                        <label for="etype">Type
                        <select name="etype" id="etype" style="width:8em;">
                            <?php
                                 if (isset($_SESSION['FORMS']['FormEditEvent']['Type']))
                                 {
                                     switch (strtolower($_SESSION['FORMS']['FormEditEvent']['Type']))
                                     {
                                        case 'w':
                                            echo "<option value='R' >Regular</option>";
                                            echo "<option value='A' >AGM</option>";
                                            echo "<option value='W' selected='selected'>Whiffette</option>";
                                            break;

                                        case 'a':
                                            echo "<option value='R' >Regular</option>";
                                            echo "<option value='A' selected='selected'>AGM</option>";
                                            echo "<option value='W' >Whiffette</option>";
                                            break;

                                        case 'r':
                                        default:
                                            echo "<option value='R' selected='selected'>Regular</option>";
                                            echo "<option value='A' >AGM</option>";
                                            echo "<option value='W' >Whiffette</option>";
                                     }
                                 }
                                 else
                                 {
                                      echo "<option value='R' selected='selected'>Regular</option>";
                                      echo "<option value='A' >AGM</option>";
                                      echo "<option value='W' >Whiffette</option>";
                                 }
                            ?>
                        </select> </label>

                        <label for="estatus">Status
                        <select name="estatus" id="estatus" style="width:8em;">
                            <?php
                                 if (isset($_SESSION['FORMS']['FormEditEvent']['Status']))
                                 {
                                     switch (strtolower($_SESSION['FORMS']['FormEditEvent']['Status']))
                                     {
                                        case 'u':
                                            echo "<option value='N' >Normal</option>";
                                            echo "<option value='U' selected='selected'>Upcoming</option>";
                                            echo "<option value='B' >Blocked</option>";
                                            echo "<option value='C' >Cancelled</option>";
                                            break;

                                        case 'b':
                                            echo "<option value='N' >Normal</option>";
                                            echo "<option value='U' >Upcoming</option>";
                                            echo "<option value='B' selected='selected'>Blocked</option>";
                                            echo "<option value='C' >Cancelled</option>";
                                            break;

                                        case 'c':
                                            echo "<option value='N' >Normal</option>";
                                            echo "<option value='U' >Upcoming</option>";
                                            echo "<option value='B' >Blocked</option>";
                                            echo "<option value='C' selected='selected'>Cancelled</option>";
                                            break;

                                        case 'n':
                                        default:
                                            echo "<option value='N' selected='selected'>Normal</option>";
                                            echo "<option value='U' >Upcoming</option>";
                                            echo "<option value='B' >Blocked</option>";
                                            echo "<option value='C' >Cancelled</option>";
                                     }
                                 }
                                 else
                                 {
                                      echo "<option value='N' selected='selected'>Normal</option>";
                                      echo "<option value='U' >Upcoming</option>";
                                      echo "<option value='B' >Blocked</option>";
                                      echo "<option value='C' >Cancelled</option>";
                                 }
                            ?>
                        </select> </label>

                   </div>

                    <div class="twoper">
                        <label for="efeemem">Fee Member
                        <input name="efeemem" type="text" id="efeemem" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['FeeMember'])) { echo $_SESSION['FORMS']['FormEditEvent']['FeeMember']; } ?>"  /> </label>


                        <label for="efeeguest">Fee Guest
                        <input name="efeeguest" type="text" id="efeeguest" value="<?php if (isset($_SESSION['FORMS']['FormEditEvent']['FeeGuest'])) { echo $_SESSION['FORMS']['FormEditEvent']['FeeGuest']; } ?>" /> </label>

                    </div>

                    <div class="oneper">
                        <label for="edescription">Description
                        <textarea rows=15 cols=10 name="edescription" id="edescription" >
                            <?php if (isset($_SESSION['FORMS']['FormEditEvent']['Description'])) { echo $_SESSION['FORMS']['FormEditEvent']['Description']; } ?>
                        </textarea></label>

                    </div>

                    <div class="oneper">
                        <input type="submit" name="EditEvent" value="Edit Event" class="button"/>
                    </div>

                </fieldset>
            </form>

            <br />

            <?php
            if (isset($_SESSION['ERRMSG_ARR']))
            {
                echo '<p class="err">Please correct the following errors: </p>';

                $errmsg_arr = $_SESSION['ERRMSG_ARR'];
                foreach ($errmsg_arr as $value) {
                    echo "<p class='err'>- $value</p>";
                }

                unset ($_SESSION['ERRMSG_ARR']);
            }
            ?>


        </div>

    </body>
</html>
<?php

    require_once('App-End.php');
?>

<!-- Designed: Jose Trujillo - 2011 -->